//
//  TCHeaderTableViewCell.m
//  Project_B
//
//  Created by dllo on 15/11/27.
//  Copyright © 2015年 张闯. All rights reserved.
//

#import "TCHeaderTableViewCell.h"
#import "UIImageView+WebCache.h"
#define WIDTH [[UIScreen mainScreen] bounds].size.width / 375
#define HEIGHT [[UIScreen mainScreen] bounds].size.height / 667

@interface TCHeaderTableViewCell ()
@property (nonatomic, strong)UILabel *label;
@property (nonatomic, strong)UILabel *titlelabel;
@property (nonatomic, strong)UILabel *fromlabel;
@property (nonatomic, strong)UILabel *replylabel;
@property (nonatomic, strong)UIImageView *nameimage;
@property (nonatomic, strong)UILabel *namelabel;
@property (nonatomic, strong)UILabel *timelabel;
@property (nonatomic, strong)UILabel *linelabel;
@end

@implementation TCHeaderTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.label = [[UILabel alloc]init];
        [self.label setFont:[UIFont systemFontOfSize:14]];
        self.label.textColor = [UIColor grayColor];
        self.label.numberOfLines = 0;
//        self.label.textColor = [UIColor grayColor];
//        self.label.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:self.label];

        self.titlelabel = [[UILabel alloc]init];
        self.titlelabel.textColor = [UIColor colorWithRed:60.0 / 255 green:149.0 / 255 blue:58.0 / 255 alpha:1];
        self.titlelabel.numberOfLines = 0;
        [self.contentView addSubview:self.titlelabel];
        
        self.fromlabel = [[UILabel alloc]init];
        [self.fromlabel setFont:[UIFont systemFontOfSize:13]];
        self.fromlabel.textColor = [UIColor orangeColor];
        [self.contentView addSubview:self.fromlabel];
        
        self.replylabel = [[UILabel alloc]init];
        [self.replylabel setFont:[UIFont systemFontOfSize:13]];
        self.replylabel.textColor = [UIColor grayColor];
        self.replylabel.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:self.replylabel];
        
        self.namelabel = [[UILabel alloc]init];
        [self.namelabel setFont:[UIFont systemFontOfSize:13]];
        self.namelabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:self.namelabel];
        
        self.nameimage = [[UIImageView alloc]init];
//        self.nameimage.layer.cornerRadius = 8;
        [self.contentView addSubview:self.nameimage];
        
        self.timelabel = [[UILabel alloc]init];
        [self.timelabel setFont:[UIFont systemFontOfSize:13]];
        self.timelabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:self.timelabel];
        
        self.linelabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.linelabel];
        self.linelabel.backgroundColor = [UIColor grayColor];
    }
    return self;
}
+ (CGFloat)heightWithText:(NSString *)text
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    CGSize size = CGSizeMake(355*WIDTH, 2000*HEIGHT);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.titlelabel.frame = CGRectMake(10*WIDTH, 10*HEIGHT, 355*WIDTH, 40*HEIGHT);
    self.fromlabel.frame = CGRectMake(15*WIDTH, 55*HEIGHT, 150*WIDTH, 30*HEIGHT);
    self.replylabel.frame = CGRectMake(200*WIDTH, 55*HEIGHT, 160*WIDTH, 30*HEIGHT);
    self.linelabel.frame = CGRectMake(10*WIDTH, 90*HEIGHT, 355*WIDTH, 0.5);
    self.nameimage.frame = CGRectMake(10*WIDTH, 110*HEIGHT, 50*WIDTH, 50*HEIGHT);
    self.namelabel.frame = CGRectMake(65*WIDTH, 110*HEIGHT, 100*WIDTH, 25*HEIGHT);
    self.timelabel.frame = CGRectMake(65*WIDTH, 140*HEIGHT, 100*WIDTH, 25*HEIGHT);
    CGFloat h = [[self class]heightWithText:self.label.text];
    self.label.frame = CGRectMake(10*WIDTH, 170*HEIGHT, self.contentView.frame.size.width-20, h);
}
- (void)setDic:(NSDictionary *)dic
{
    if (self.dic != dic) {
        _dic = dic;
    }
    self.titlelabel.text = dic[@"data"][@"title"];
    self.fromlabel.text = [NSString stringWithFormat:@"%@ >",dic[@"data"][@"shareTxt"]];
    self.replylabel.text = [NSString stringWithFormat:@"%@个回复",dic[@"data"][@"replytopic"]];
    [self.nameimage sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][@"headicon"]] placeholderImage:[UIImage imageNamed:@"zhanwei.png"]];
    self.namelabel.text = dic[@"data"][@"nickname"];
    self.timelabel.text = dic[@"data"][@"createdate"];
    self.label.text = dic[@"data"][@"content"];

//    self.linelabel.text = @"zhanwei.png";

}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
